﻿namespace Vdc.Grid
{
    using Vdc.Interface;
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    internal class GridFooter : WebControl, INamingContainer
    {
        internal HtmlContainer AddMultiRecordLinkContainer;
        internal HyperLink AddRecordLink;
        internal HtmlContainer AddRecordLinkContainer;
        private bool addSeparator;
        internal HtmlContainer FilterLinksContainer;
        private Vdc.Grid.Grid grid;
        internal bool isTop;
        internal VdcTextBox ManualPagingTextbox;
        internal VdcDropDownList PageSizeSelector;

        public GridFooter(Vdc.Grid.Grid _grid, bool _isTop)
        {
            this.grid = _grid;
            this.isTop = _isTop;
            this.ID = this.GetFooterID();
        }

        protected virtual HtmlContainer CreateActionLinks()
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gFALC"
            };
            if (this.grid.AllowFiltering && ((((this.grid.FilteringSettings.FilterLinksPosition == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.FilteringSettings.FilterLinksPosition == GridElementPosition.Top) && this.isTop)) || (this.grid.FilteringSettings.FilterLinksPosition == GridElementPosition.TopAndBottom)))
            {
                HtmlContainer child = this.CreateActionLinksSeparator();
                if (this.grid.FilterType == GridFilterType.ProgrammaticOnly)
                {
                    child.Style["display"] = "none";
                }
                else if (!this.addSeparator)
                {
                    child.Style["visibility"] = "hidden";
                    this.addSeparator = true;
                }
                container.Controls.Add(child);
                this.FilterLinksContainer = new HtmlContainer();
                this.FilterLinksContainer.ID = "ob_" + this.grid.GridID + "FLC" + (!this.isTop ? "" : "_T");
                this.FilterLinksContainer.CssClass = "ob_gFAL";
                Literal literal = new Literal {
                    Text = "&#160;"
                };
                this.FilterLinksContainer.Controls.Add(literal);
                if (this.grid.FilteringSettings.InitialState == GridFilterState.Hidden)
                {
                    if (!string.IsNullOrEmpty(this.grid.FilterExpression))
                    {
                        this.grid.FilteringButtonsConfigurationValue = "2,3,4";
                    }
                }
                else
                {
                    if (!this.grid.IsCallback && (string.IsNullOrEmpty(this.grid.FilteringButtonsConfigurationValue) || (this.grid.FilteringButtonsConfigurationValue == "1")))
                    {
                        this.grid.FilteringButtonsConfigurationValue = "2,3";
                    }
                    if (!string.IsNullOrEmpty(this.grid.FilterExpression))
                    {
                        this.grid.FilteringButtonsConfigurationValue = "2,3,4";
                    }
                }
                if (this.grid.FilteringButtonsConfiguration != null)
                {
                    this.grid.FilteringButtonsConfiguration.Value = this.grid.FilteringButtonsConfigurationValue;
                }
                if (string.IsNullOrEmpty(this.grid.FilteringButtonsConfigurationValue))
                {
                    if (string.IsNullOrEmpty(this.grid.TemplateSettings.FilterShowButton_TemplateId))
                    {
                        HyperLink link = new HyperLink {
                            CssClass = this.grid.CssSettings.CSSActionLinkFooter,
                            Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Filter_ShowLink)
                        };
                        if (this.grid.CallbackMode)
                        {
                            link.Attributes["href"] = "javascript: //";
                            link.Attributes["onclick"] = this.grid.GridID + ".showFilter();return false;";
                        }
                        else
                        {
                            link.Attributes["href"] = "javascript: " + this.grid.GridID + ".showFilter();";
                        }
                        this.FilterLinksContainer.Controls.Add(link);
                    }
                    else
                    {
                        GridTemplate template = this.grid.CreateTemplate(this.grid.TemplateSettings.FilterShowButton_TemplateId, "", null, null, 0, 0);
                        GridCellSpanContainer container3 = new GridCellSpanContainer();
                        container3.Controls.Add(template);
                        this.FilterLinksContainer.Controls.Add(container3);
                    }
                }
                else
                {
                    string[] strArray = this.grid.FilteringButtonsConfigurationValue.Split(new char[] { ',' });
                    int num = 0;
                    this.grid.FilteringButtonsConfigurationValue = "";
                    foreach (string str in strArray)
                    {
                        if (num > 0)
                        {
                            Literal literal2 = new Literal {
                                Text = "<span class=\"ob_gFBSp\"> | </span>"
                            };
                            this.FilterLinksContainer.Controls.Add(literal2);
                        }
                        string str2 = str;
                        if (str2 != null)
                        {
                            if (!(str2 == "1"))
                            {
                                if (str2 == "2")
                                {
                                    goto Label_0586;
                                }
                                if (str2 == "3")
                                {
                                    goto Label_0703;
                                }
                                if (str2 == "4")
                                {
                                    goto Label_0880;
                                }
                            }
                            else
                            {
                                if (string.IsNullOrEmpty(this.grid.TemplateSettings.FilterShowButton_TemplateId))
                                {
                                    HyperLink link2 = new HyperLink {
                                        CssClass = this.grid.CssSettings.CSSActionLinkFooter,
                                        Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Filter_ShowLink)
                                    };
                                    if (this.grid.CallbackMode)
                                    {
                                        link2.Attributes["href"] = "javascript: //";
                                        link2.Attributes["onclick"] = this.grid.GridID + ".showFilter();return false;";
                                    }
                                    else
                                    {
                                        link2.Attributes["href"] = "javascript: " + this.grid.GridID + ".showFilter();";
                                    }
                                    this.FilterLinksContainer.Controls.Add(link2);
                                }
                                else
                                {
                                    GridTemplate template2 = this.grid.CreateTemplate(this.grid.TemplateSettings.FilterShowButton_TemplateId, "", null, null, 0, 0);
                                    GridCellSpanContainer container4 = new GridCellSpanContainer();
                                    container4.Controls.Add(template2);
                                    this.FilterLinksContainer.Controls.Add(container4);
                                }
                                if (this.grid.FilteringButtonsConfigurationValue != string.Empty)
                                {
                                    this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + ",";
                                }
                                this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + "1";
                            }
                        }
                        goto Label_09F8;
                    Label_0586:
                        if (string.IsNullOrEmpty(this.grid.TemplateSettings.FilterApplyButton_TemplateId))
                        {
                            HyperLink link3 = new HyperLink {
                                CssClass = this.grid.CssSettings.CSSActionLinkFooter,
                                Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Filter_ApplyLink)
                            };
                            if (this.grid.CallbackMode)
                            {
                                link3.Attributes["href"] = "javascript: //";
                                link3.Attributes["onclick"] = this.grid.GridID + ".filter();return false;";
                            }
                            else
                            {
                                link3.Attributes["href"] = "javascript: " + this.grid.GridID + ".filter();";
                            }
                            this.FilterLinksContainer.Controls.Add(link3);
                        }
                        else
                        {
                            GridTemplate template3 = this.grid.CreateTemplate(this.grid.TemplateSettings.FilterApplyButton_TemplateId, "", null, null, 0, 0);
                            GridCellSpanContainer container5 = new GridCellSpanContainer();
                            container5.Controls.Add(template3);
                            this.FilterLinksContainer.Controls.Add(container5);
                        }
                        if (this.grid.FilteringButtonsConfigurationValue != string.Empty)
                        {
                            this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + ",";
                        }
                        this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + "2";
                        goto Label_09F8;
                    Label_0703:
                        if (string.IsNullOrEmpty(this.grid.TemplateSettings.FilterHideButton_TemplateId))
                        {
                            HyperLink link4 = new HyperLink {
                                CssClass = this.grid.CssSettings.CSSActionLinkFooter,
                                Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Filter_HideLink)
                            };
                            if (this.grid.CallbackMode)
                            {
                                link4.Attributes["href"] = "javascript: //";
                                link4.Attributes["onclick"] = this.grid.GridID + ".hideFilter();return false;";
                            }
                            else
                            {
                                link4.Attributes["href"] = "javascript: " + this.grid.GridID + ".hideFilter();";
                            }
                            this.FilterLinksContainer.Controls.Add(link4);
                        }
                        else
                        {
                            GridTemplate template4 = this.grid.CreateTemplate(this.grid.TemplateSettings.FilterHideButton_TemplateId, "", null, null, 0, 0);
                            GridCellSpanContainer container6 = new GridCellSpanContainer();
                            container6.Controls.Add(template4);
                            this.FilterLinksContainer.Controls.Add(container6);
                        }
                        if (this.grid.FilteringButtonsConfigurationValue != string.Empty)
                        {
                            this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + ",";
                        }
                        this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + "3";
                        goto Label_09F8;
                    Label_0880:
                        if (string.IsNullOrEmpty(this.grid.TemplateSettings.FilterRemoveButton_TemplateId))
                        {
                            HyperLink link5 = new HyperLink {
                                CssClass = this.grid.CssSettings.CSSActionLinkFooter,
                                Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Filter_RemoveLink)
                            };
                            if (this.grid.CallbackMode)
                            {
                                link5.Attributes["href"] = "javascript: //";
                                link5.Attributes["onclick"] = this.grid.GridID + ".removeFilter();return false;";
                            }
                            else
                            {
                                link5.Attributes["href"] = "javascript: " + this.grid.GridID + ".removeFilter();";
                            }
                            this.FilterLinksContainer.Controls.Add(link5);
                        }
                        else
                        {
                            GridTemplate template5 = this.grid.CreateTemplate(this.grid.TemplateSettings.FilterRemoveButton_TemplateId, "", null, null, 0, 0);
                            GridCellSpanContainer container7 = new GridCellSpanContainer();
                            container7.Controls.Add(template5);
                            this.FilterLinksContainer.Controls.Add(container7);
                        }
                        if (this.grid.FilteringButtonsConfigurationValue != string.Empty)
                        {
                            this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + ",";
                        }
                        this.grid.FilteringButtonsConfigurationValue = this.grid.FilteringButtonsConfigurationValue + "4";
                    Label_09F8:
                        num++;
                    }
                }
                if (this.grid.FilterType == GridFilterType.ProgrammaticOnly)
                {
                    this.FilterLinksContainer.Style["display"] = "none";
                }
                container.Controls.Add(this.FilterLinksContainer);
            }
            if ((this.grid.AllowMultiRecordAdding || this.grid.AllowMultiRecordEditing) || this.grid.AllowMultiRecordDeleting)
            {
                HtmlContainer container8 = this.CreateActionLinksSeparator();
                container8.Style["display"] = "none";
                container.Controls.Add(container8);
                this.AddMultiRecordLinkContainer = new HtmlContainer();
                this.AddMultiRecordLinkContainer.ID = "ob_" + this.grid.GridID + "SCAllCont";
                this.AddMultiRecordLinkContainer.CssClass = "ob_gFAL";
                this.AddMultiRecordLinkContainer.Style["display"] = "none";
                if (string.IsNullOrEmpty(this.grid.TemplateSettings.MultiRecordSaveCancel_TemplateId))
                {
                    HyperLink link6 = new HyperLink {
                        CssClass = this.grid.CssSettings.CSSActionLinkFooter
                    };
                    link6.Attributes["href"] = "javascript: " + this.grid.GridID + ".saveAll()";
                    link6.Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.SaveAllLink);
                    Literal literal3 = new Literal {
                        Text = "&#160;|&#160;"
                    };
                    HyperLink link7 = new HyperLink {
                        CssClass = this.grid.CssSettings.CSSActionLinkFooter
                    };
                    link7.Attributes["href"] = "javascript: " + this.grid.GridID + ".cancelAll()";
                    link7.Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.CancelAllLink);
                    this.AddMultiRecordLinkContainer.Controls.Add(link6);
                    this.AddMultiRecordLinkContainer.Controls.Add(literal3);
                    this.AddMultiRecordLinkContainer.Controls.Add(link7);
                }
                else
                {
                    GridTemplate template6 = this.grid.CreateTemplate(this.grid.TemplateSettings.MultiRecordSaveCancel_TemplateId, "", null, null, 0, 0);
                    this.AddMultiRecordLinkContainer.Controls.Add(template6);
                }
                container.Controls.Add(this.AddMultiRecordLinkContainer);
            }
            if (this.grid.AllowAddingRecords && ((((this.grid.AddEditDeleteSettings.AddLinksPosition == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.AddEditDeleteSettings.AddLinksPosition == GridElementPosition.Top) && this.isTop)) || (this.grid.AddEditDeleteSettings.AddLinksPosition == GridElementPosition.TopAndBottom)))
            {
                HtmlContainer container9 = this.CreateActionLinksSeparator();
                container.Controls.Add(container9);
                if (!this.addSeparator)
                {
                    container9.Style["visibility"] = "hidden";
                    this.addSeparator = true;
                }
                this.AddRecordLinkContainer = new HtmlContainer();
                this.AddRecordLinkContainer.ID = "ob_" + this.grid.GridID + "ALC" + (!this.isTop ? "" : "_T");
                this.AddRecordLinkContainer.CssClass = "ob_gFAL";
                if (string.IsNullOrEmpty(this.grid.TemplateSettings.NewRecord_TemplateId))
                {
                    Literal literal4 = new Literal {
                        Text = "&#160;"
                    };
                    this.AddRecordLinkContainer.Controls.Add(literal4);
                    this.AddRecordLink = new HyperLink();
                    this.AddRecordLink.CssClass = this.grid.CssSettings.CSSActionLinkFooter;
                    if (this.grid.CallbackMode)
                    {
                        this.AddRecordLink.Attributes["href"] = "javascript: //";
                        this.AddRecordLink.Attributes["onclick"] = this.grid.GridID + ".addRecord(" + ((this.grid.AddEditDeleteSettings.NewRecordPosition == GridDynamicElementPosition.Dynamic) ? (!this.isTop ? "1" : "2") : "") + "); return false;";
                    }
                    else
                    {
                        this.AddRecordLink.Attributes["href"] = "javascript: " + this.grid.GridID + ".addRecord(" + ((this.grid.AddEditDeleteSettings.NewRecordPosition == GridDynamicElementPosition.Dynamic) ? (!this.isTop ? "1" : "2") : "") + ");";
                    }
                    this.AddRecordLink.ID = "ob_" + this.grid.GridID + "AddButton" + (!this.isTop ? "" : "_T");
                    this.AddRecordLink.Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.AddLink);
                    this.AddRecordLinkContainer.Controls.Add(this.AddRecordLink);
                }
                else
                {
                    GridTemplate template7 = this.grid.CreateTemplate(this.grid.TemplateSettings.NewRecord_TemplateId, !this.isTop ? "1" : "2", null, null, 0, 0, true);
                    this.AddRecordLinkContainer.Controls.Add(template7);
                }
                container.Controls.Add(this.AddRecordLinkContainer);
            }
            return container;
        }

        protected virtual HtmlContainer CreateActionLinksSeparator()
        {
            return new HtmlContainer { CssClass = "ob_gALFS", Text = " - " };
        }

        protected override void CreateChildControls()
        {
            if (!this.grid.IsDesignTimeRender)
            {
                this.CssClass = !this.isTop ? "ob_gFCont" : ("ob_gFContT" + (!this.grid.AllowGrouping ? "" : " ob_gFContTWG"));
            }
            else
            {
                this.CssClass = "ob_gFCont_F_D";
            }
            if (this.isTop && !string.IsNullOrEmpty(this.grid.TemplateSettings.HeadingTemplateId))
            {
                this.CssClass = this.CssClass + " ob_gFContTWT";
            }
            if ((this.isTop && !string.IsNullOrEmpty(this.grid.TemplateSettings.HeadingTemplateId)) && this.grid.AllowGrouping)
            {
                this.CssClass = this.CssClass + " ob_gFContTWT_WG";
            }
            if (this.grid.IsDesignTimeRender && this.grid.UseEmbeddedImages)
            {
                base.Style["background-image"] = "url(" + this.grid.ImagesURL.Footer_Content + ")";
            }
            HtmlContainer child = new HtmlContainer {
                CssClass = "ob_gPSTT"
            };
            if (this.grid.AllowPageSizeSelection && ((((this.grid.PagingSettings.PageSizeSelectorPosition == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.PagingSettings.PageSizeSelectorPosition == GridElementPosition.Top) && this.isTop)) || (this.grid.PagingSettings.PageSizeSelectorPosition == GridElementPosition.TopAndBottom)))
            {
                child.Text = GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Paging_PageSizeText);
                HtmlContainer container2 = new HtmlContainer {
                    CssClass = "ob_gPSTD"
                };
                if (!this.grid.CallbackMode || !this.grid.IsCallback)
                {
                    container2.Controls.Add(this.CreatePageSizeSelector());
                }
                child.Controls.Add(container2);
            }
            else
            {
                child.Style["display"] = "none";
            }
            this.Controls.Add(child);
            this.addSeparator = false;
            HtmlContainer container3 = new HtmlContainer {
                CssClass = "ob_gFEC"
            };
            container3.Controls.Add(this.CreatePager());
            container3.Controls.Add(this.CreateActionLinks());
            this.Controls.Add(container3);
            if (this.isTop)
            {
                HtmlContainer container4 = new HtmlContainer();
                HtmlContainer container5 = new HtmlContainer();
                container4.CssClass = "ob_gFContTL";
                container5.CssClass = "ob_gFContTR";
                this.Controls.Add(container4);
                this.Controls.Add(container5);
            }
        }

        protected virtual HtmlContainer CreateManualPagingCell()
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gMPS"
            };
            if (string.IsNullOrEmpty(this.grid.TemplateSettings.ManualPagingTemplateId))
            {
                this.ManualPagingTextbox = new VdcTextBox();
                this.ManualPagingTextbox.ID = "ob_" + this.grid.GridID + "JTPT" + (!this.isTop ? "" : "_T");
                this.ManualPagingTextbox.Width = Unit.Pixel(30);
                this.ManualPagingTextbox.FolderStyle = this.grid.GetInterfaceFolderStyle_TextBox();
                HyperLink link = new HyperLink();
                link.Attributes["href"] = "javascript: //";
                link.CssClass = this.grid.CssSettings.CSSActionLinkFooter;
                link.Attributes["onclick"] = this.grid.GridID + ".jumpToPage(" + (!this.isTop ? "1" : "2") + ")";
                link.Text = this.grid.LocalizationSettings.Paging_ManualPagingLink;
                HtmlContainer container2 = new HtmlContainer();
                HtmlContainer container3 = new HtmlContainer();
                container2.CssClass = "ob_gMPST";
                container3.CssClass = "ob_gMPSL";
                container2.Controls.Add(this.ManualPagingTextbox);
                container3.Controls.Add(link);
                container.Controls.Add(container2);
                container.Controls.Add(container3);
                return container;
            }
            GridTemplate child = this.grid.CreateTemplate(this.grid.TemplateSettings.ManualPagingTemplateId, "", null, null, 0, 0);
            container.Controls.Add(child);
            return container;
        }

        protected virtual HtmlContainer CreatePager()
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gFP"
            };
            if (this.grid.AllowPaging && ((((this.grid.PagingSettings.Position == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.PagingSettings.Position == GridElementPosition.Top) && this.isTop)) || (this.grid.PagingSettings.Position == GridElementPosition.TopAndBottom)))
            {
                string imgUrl = !this.isTop ? this.grid.ImagesURL.PageNavigation_First_Normal : this.grid.ImagesURL.PageNavigation_First_Normal_Top;
                string str2 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Previous_Normal : this.grid.ImagesURL.PageNavigation_Previous_Normal_Top;
                if (this.grid.CurrentPageIndex == 0)
                {
                    imgUrl = !this.isTop ? this.grid.ImagesURL.PageNavigation_First_Disabled : this.grid.ImagesURL.PageNavigation_First_Disabled_Top;
                    str2 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Previous_Disabled : this.grid.ImagesURL.PageNavigation_Previous_Disabled_Top;
                }
                string str3 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Next_Normal : this.grid.ImagesURL.PageNavigation_Next_Normal_Top;
                string str4 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Last_Normal : this.grid.ImagesURL.PageNavigation_Last_Normal_Top;
                if (this.grid.CurrentPageIndex >= ((((double) this.grid.TotalRecords) / ((double) this.grid.PageSize)) - 1.0))
                {
                    str3 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Next_Disabled : this.grid.ImagesURL.PageNavigation_Next_Disabled_Top;
                    str4 = !this.isTop ? this.grid.ImagesURL.PageNavigation_Last_Disabled : this.grid.ImagesURL.PageNavigation_Last_Disabled_Top;
                }
                if (this.grid.AllowManualPaging)
                {
                    container.Controls.Add(this.CreateManualPagingCell());
                }
                if (this.grid.ShowTotalNumberOfPages)
                {
                    container.Controls.Add(this.CreateTotalNumberOfPagesContainer());
                }
                container.Controls.Add(this.CreatePagingButton(str4));
                container.Controls.Add(this.CreatePagingButton(str3));
                container.Controls.Add(this.CreatePagingLinks());
                container.Controls.Add(this.CreatePagingButton(str2));
                container.Controls.Add(this.CreatePagingButton(imgUrl));
                this.addSeparator = true;
            }
            else if (!this.grid.PagingSettings.ShowRecordsCount)
            {
                container.Style["display"] = "none";
            }
            HtmlContainer child = new HtmlContainer {
                CssClass = "ob_gFPT"
            };
            bool flag = false;
            if (this.grid.PagingSettings.ShowRecordsCount && ((((this.grid.PagingSettings.Position == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.PagingSettings.Position == GridElementPosition.Top) && this.isTop)) || (this.grid.PagingSettings.Position == GridElementPosition.TopAndBottom)))
            {
                string[] strArray = new string[] { GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Paging_RecordsText), " ", (this.grid.TotalRecords > 0) ? this.grid.StartRowIndex.ToString() : "0", " ", GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Paging_ToText), " ", ((((this.grid.StartRowIndex + (this.grid.GetPageSize(true) * ((this.grid.ScrollingSettings.EnableVirtualScrolling && !this.grid.ScrollingSettings.UsePagingForVirtualScrolling) ? (this.grid.CurrentPageIndex + 1) : 1))) - 1) <= this.grid.TotalRecords) ? ((this.grid.StartRowIndex + (this.grid.GetPageSize(true) * ((this.grid.ScrollingSettings.EnableVirtualScrolling && !this.grid.ScrollingSettings.UsePagingForVirtualScrolling) ? (this.grid.CurrentPageIndex + 1) : 1))) - 1) : this.grid.TotalRecords).ToString(), " ", GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Paging_OfText), " ", this.grid.TotalRecords.ToString(), "&#160;" };
                child.Text = string.Concat(strArray);
                flag = true;
            }
            if ((this.grid.PagingSettings.ShowRecordsCount && this.grid.AllowPaging) && ((((this.grid.PagingSettings.Position == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.PagingSettings.Position == GridElementPosition.Top) && this.isTop)) || (this.grid.PagingSettings.Position == GridElementPosition.TopAndBottom)))
            {
                child.Text = child.Text + "-&#160;";
                flag = true;
            }
            if (this.grid.AllowPaging && ((((this.grid.PagingSettings.Position == GridElementPosition.Bottom) && !this.isTop) || ((this.grid.PagingSettings.Position == GridElementPosition.Top) && this.isTop)) || (this.grid.PagingSettings.Position == GridElementPosition.TopAndBottom)))
            {
                child.Text = child.Text + GridEncodingHelper.XMLCdataEncode(this.grid.LocalizationSettings.Paging_PagesText) + "&#160;";
                flag = true;
            }
            if (flag)
            {
                container.Controls.Add(child);
                this.addSeparator = true;
            }
            return container;
        }

        protected virtual VdcDropDownList CreatePageSizeSelector()
        {
            this.PageSizeSelector = new VdcDropDownList();
            this.PageSizeSelector.ID = this.GetPageSizeSelectorID();
            this.PageSizeSelector.Width = Unit.Percentage(100.0);
            this.PageSizeSelector.MenuWidth = Unit.Pixel(70);
            this.PageSizeSelector.FolderStyle = this.grid.GetInterfaceFolderStyle_DropDownList();
            this.PageSizeSelector.CssSettings.ItemsContainer = this.PageSizeSelector.CssSettings.ItemsContainer + " ob_gPSTDIC";
            string[] strArray = this.grid.PageSizeOptions.Split(new char[] { ',' });
            string str = "," + this.grid.PageSizeOptions + ",";
            bool flag = false;
            bool flag2 = false;
            if (str.IndexOf("," + this.grid.PageSize.ToString() + ",") == -1)
            {
                flag = true;
                flag2 = true;
                this.grid.PageSizeOptions = "";
            }
            for (int i = 0; i < strArray.Length; i++)
            {
                if (flag2 && (i > 0))
                {
                    this.grid.PageSizeOptions = this.grid.PageSizeOptions + ",";
                }
                if (flag && (this.grid.PageSize < int.Parse(strArray[i])))
                {
                    ListItem item = new ListItem {
                        Value = this.grid.PageSize.ToString(),
                        Text = (this.grid.PageSize != -1) ? this.grid.PageSize.ToString() : this.grid.LocalizationSettings.Paging_PageSizeOptions_All,
                        Selected = true
                    };
                    this.PageSizeSelector.Items.Add(item);
                    flag = false;
                    this.grid.PageSizeOptions = this.grid.PageSizeOptions + this.grid.PageSize.ToString() + ",";
                }
                ListItem item2 = new ListItem {
                    Value = strArray[i],
                    Text = (strArray[i] != "-1") ? strArray[i].ToString() : this.grid.LocalizationSettings.Paging_PageSizeOptions_All
                };
                if (strArray[i] == this.grid.PageSize.ToString())
                {
                    item2.Selected = true;
                }
                this.PageSizeSelector.Items.Add(item2);
                if (flag2)
                {
                    this.grid.PageSizeOptions = this.grid.PageSizeOptions + strArray[i];
                }
            }
            return this.PageSizeSelector;
        }

        protected virtual HtmlContainer CreatePagingButton(string imgUrl)
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gPBC"
            };
            Image child = new Image {
                ImageUrl = imgUrl
            };
            child.Attributes["alt"] = "";
            container.Controls.Add(child);
            return container;
        }

        protected virtual HtmlContainer CreatePagingLink(string text, string cssClass)
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = cssClass,
                Text = text
            };
            if (this.grid.IsDesignTimeRender && this.grid.UseEmbeddedImages)
            {
                if (cssClass == this.grid.CssSettings.CSSNavigationLink)
                {
                    container.Style["background-image"] = "url(" + this.grid.ImagesURL.PageNumber_Normal + ")";
                    return container;
                }
                if (cssClass == this.grid.CssSettings.CSSNavigationText)
                {
                    container.Style["background-image"] = "url(" + this.grid.ImagesURL.PageNumber_Selected + ")";
                }
            }
            return container;
        }

        protected virtual HtmlContainer CreatePagingLinks()
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gPLC"
            };
            if ((this.grid.TotalRecords != 0) && (this.grid.PageSize != -1))
            {
                int num = (this.grid.CurrentPageIndex - ((this.grid.NumberOfPagesShownInFooter / 2) - (((this.grid.NumberOfPagesShownInFooter % 2) == 0) ? 1 : 0))) - 1;
                for (int i = 1; i <= (this.grid.NumberOfPagesShownInFooter / 2); i++)
                {
                    if (((this.grid.CurrentPageIndex + i) * this.grid.GetPageSize(true)) >= this.grid.TotalRecords)
                    {
                        num--;
                    }
                }
                int num3 = 0;
                while ((((num + 1) * this.grid.GetPageSize(true)) < this.grid.TotalRecords) && (num3 < this.grid.NumberOfPagesShownInFooter))
                {
                    num++;
                    if (num >= 0)
                    {
                        if (num3 > 0)
                        {
                            container.Controls.Add(this.CreatePagingLink("|", this.grid.CssSettings.CSSNavigationSeparator));
                        }
                        if (num != this.grid.CurrentPageIndex)
                        {
                            int num4 = num + 1;
                            container.Controls.Add(this.CreatePagingLink(num4.ToString(), this.grid.CssSettings.CSSNavigationLink));
                        }
                        else
                        {
                            int num5 = num + 1;
                            container.Controls.Add(this.CreatePagingLink(num5.ToString(), this.grid.CssSettings.CSSNavigationText));
                        }
                        num3++;
                    }
                }
                return container;
            }
            container.Controls.Add(this.CreatePagingLink("1", this.grid.CssSettings.CSSNavigationText));
            return container;
        }

        protected HtmlContainer CreateTotalNumberOfPagesContainer()
        {
            HtmlContainer container = new HtmlContainer {
                CssClass = "ob_gTNOP"
            };
            int num = this.grid.TotalRecords / this.grid.GetPageSize(true);
            if ((this.grid.TotalRecords % this.grid.GetPageSize(true)) > 0)
            {
                num++;
            }
            container.Text = this.grid.LocalizationSettings.Paging_TotalNumberOfPages.Replace("XXXXX", num.ToString());
            return container;
        }

        internal void ForceEnsureChildControls()
        {
            this.EnsureChildControls();
        }

        protected virtual string GetFooterID()
        {
            return ("ob_" + this.grid.GridID + "FooterContainer" + (!this.isTop ? "" : "_Top"));
        }

        internal virtual string GetPageSizeSelectorID()
        {
            return ("ob_" + this.grid.GridID + "PageSizeSelector" + (!this.isTop ? "" : "_Top"));
        }

        protected override HtmlTextWriterTag TagKey
        {
            get
            {
                return HtmlTextWriterTag.Div;
            }
        }
    }
}

